const { src, dest, watch,series } = require("gulp");
const ts = require("gulp-typescript");
const sourcemaps = require("gulp-sourcemaps");

const tsProject = ts.createProject("tsconfig.json");

function build() {
    const tsResult = tsProject
        .src() // or tsProject.src()
        .pipe(tsProject());
    return tsResult.js.pipe(dest("dist"));
}
function clean(){

}

function copyTemp(){
    return src('./publish-temp/**')
    .pipe(dest('dist'));
}
function buildDev() {
    tsProject
        .src()
        .pipe(sourcemaps.init())
        .pipe(tsProject())
        .pipe(sourcemaps.write("."))
        .pipe(dest("dist"));
}
function dev(cb) {
    buildDev();
    watch(
        ["src/**/*.ts"],
        {
            delay: 5000,
        },
        function(cb){
            buildDev();
            cb();
        }
    );
    cb();
}
exports.dev = dev;
exports.default = series(build,copyTemp);
